<template>
  <div class="layout-container">
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="200px" class="sidebar">
        <!-- Logo区域 -->
        <div class="logo-section">
          <div class="logo">
            <span class="logo-text">ChatApp</span>
          </div>
        </div>
        
        <!-- 导航菜单 -->
        <el-menu
          :default-active="activeMenu"
          class="sidebar-menu"
          background-color="#fdf2f8"
          text-color="#ec4899"
          active-text-color="#be185d"
          router
        >
          <el-menu-item index="/app/character-square">
            <el-icon><User /></el-icon>
            <span>角色广场</span>
          </el-menu-item>
          <el-menu-item index="/app/my-follows">
            <el-icon><Star /></el-icon>
            <span>我的关注</span>
          </el-menu-item>
          <el-menu-item index="/app/my-characters">
            <el-icon><Avatar /></el-icon>
            <span>我的角色</span>
          </el-menu-item>
         <el-menu-item index="/app/profile">
           <el-icon><Avatar /></el-icon>
           <span>个人主页</span>
         </el-menu-item>
        </el-menu>
      </el-aside>
      
      <!-- 主内容区域 -->
      <el-container direction="vertical">
        <!-- 顶部导航栏 -->
        <el-header class="top-header">
          <div class="header-content">
            <div class="header-left">
              <!-- 可以放置面包屑导航等 -->
            </div>
            <div class="header-right">
              <el-button 
                type="danger" 
                plain 
                size="small"
                @click="handleLogout"
              >
                退出登录
              </el-button>
            </div>
          </div>
        </el-header>
        
        <!-- 主内容 -->
        <el-main class="main-content">
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { User, Avatar, Star } from '@element-plus/icons-vue'
import { useUserStore } from '../stores/user'

const route = useRoute()
const router = useRouter()
const userStore = useUserStore()

// 计算当前激活的菜单项
const activeMenu = computed(() => {
  return route.path
})

// 退出登录处理
const handleLogout = async () => {
  try {
    await ElMessageBox.confirm(
      '确定要退出登录吗？',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
    )
    
    // 清除用户状态
    userStore.logout()
    
    // 跳转到登录页面
    await router.push('/login')
    
    ElMessage.success('已退出登录')
  } catch {
    // 用户取消退出
  }
}
</script>

<style scoped>
.layout-container {
  min-height: 100vh;
  background-color: #fdf2f8;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.el-container {
  height: 562.5px; /* 16:9比例，基于1000px宽度 */
  width: 1000px;
  max-width: 100%;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(236, 72, 153, 0.2);
}

.sidebar {
  background-color: #fdf2f8;
  border-right: 1px solid #f9a8d4;
  box-shadow: 2px 0 8px rgba(236, 72, 153, 0.1);
}

.logo-section {
  padding: 20px;
  border-bottom: 1px solid #f9a8d4;
  margin-bottom: 10px;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-text {
  font-size: 24px;
  font-weight: bold;
  color: #ec4899;
  text-align: center;
}

.sidebar-menu {
  border: none;
  background-color: transparent;
}

.sidebar-menu .el-menu-item {
  margin: 5px 10px;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.sidebar-menu .el-menu-item:hover {
  background-color: #fce7f3;
  color: #be185d;
}

.sidebar-menu .el-menu-item.is-active {
  background-color: #f9a8d4;
  color: #be185d;
  font-weight: 600;
}

.top-header {
  height: 60px;
  background-color: #ffffff;
  border-bottom: 1px solid #f0f0f0;
  padding: 0;
}

.header-content {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.header-left {
  flex: 1;
}

.header-right {
  display: flex;
  align-items: center;
}

.main-content {
  background-color: #fdf2f8;
  padding: 20px;
  overflow-y: auto;
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .el-container {
    height: 506.25px; /* 16:9比例，基于900px宽度 */
    width: 900px;
  }
}

@media (max-width: 768px) {
  .layout-container {
    padding: 10px;
  }
  
  .el-container {
    height: auto;
    min-height: 400px;
    flex-direction: column;
  }
  
  .sidebar {
    width: 100% !important;
    height: 80px;
    border-right: none;
    border-bottom: 1px solid #f9a8d4;
  }
  
  .logo-section {
    padding: 10px;
  }
  
  .logo-text {
    display: block;
    font-size: 20px;
  }
  
  .sidebar-menu {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    white-space: nowrap;
  }
  
  .sidebar-menu .el-menu-item {
    margin: 5px;
    min-width: 120px;
  }
}
</style>